/**
 * jims
 */
package com.jims.master.modules.physical.web;

import com.jims.master.common.data.StringData;
import com.jims.master.common.persistence.Page;
import com.jims.master.common.utils.StringUtils;
import com.jims.master.common.web.BaseController;
import com.jims.master.modules.physical.entity.TInformation;
import com.jims.master.modules.physical.service.TInformationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * t_informationController
 * @author 系统管理员
 * @version 2017-06-14
 */
@Controller
@RequestMapping(value = "${adminPath}/tinformation/t_information/tInformation")
public class TInformationController extends BaseController {

	@Autowired
	private TInformationService tInformationService;
	
	@ModelAttribute
	public TInformation get(@RequestParam(required=false) String id) {
		TInformation entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = tInformationService.get(id);
		}
		if (entity == null){
			entity = new TInformation();
		}
		return entity;
	}
	
	@RequiresPermissions("user")
	@RequestMapping(value = {"index", ""})
	public String list(TInformation tInformation, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TInformation> page = tInformationService.findPage(new Page<TInformation>(request, response), tInformation); 
		model.addAttribute("page", page);
		return "modules/tinformation/t_information/tInformationIndex";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "form")
	public String form(TInformation tInformation, Model model) {
		model.addAttribute("tInformation", tInformation);
		return "modules/tinformation/t_information/tInformationForm";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "save")
	@ResponseBody
	public StringData save(TInformation tInformation, Model model) {
	    StringData data=new StringData();
		int i=tInformationService.save(tInformation);
        if(i>0){
            data.setCode("success");
            data.setData("保存成功");
        }else{
            data.setCode("error");
            data.setData("保存失败");
        }
        return data;
	}
	@RequiresPermissions("user")
	@RequestMapping(value = "delete")
	@ResponseBody
	public StringData delete(TInformation tInformation) {
	    StringData data=new StringData();
		int i=tInformationService.delete(tInformation);
        if(i>0){
            data.setCode("success");
            data.setData("删除成功");
        }else{
            data.setCode("error");
            data.setData("删除失败");
        }
		return data;
	}

	/**
	 * 打印导检单
	 * @param tInformation
	 * @author CTQ
	 * @return
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = "print")
	@ResponseBody
	public StringData print(TInformation tInformation) {
		StringData data=new StringData();
		String printPath=tInformationService.print(tInformation);
		data.setCode("success");
		data.setData(printPath);
		return data;
	}

}